package com.xyview.fast.modules.app.controller;

import com.xyview.fast.common.util.R;
import com.xyview.fast.modules.app.annotation.Login;
import com.xyview.fast.modules.app.annotation.LoginUser;
import com.xyview.fast.modules.app.entity.UserEntity;
import com.xyview.fast.modules.app.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/app")
@Api("APP测试接口")
public class AppTestController {
    @Autowired
    private UserService userService;
    @GetMapping("userInfo")
    @ApiOperation("获取用户信息")
    public R userInfo(String mobile){
        UserEntity user= userService.queryByMobile(mobile);
        return R.ok().put("data", user);
    }
    @GetMapping("userList")
    @ApiOperation("获取用户信息")
    public R userInfos(@RequestParam Map<String, Object> params){
        List<UserEntity> list = userService.selectByMap(params);
        return R.ok().put("data", list);
    }

    @GetMapping("userJson")
    @ApiOperation("测试Json数据转换")
    public R userJson(){
        Map<String,Long> map = new HashMap<>();
        map.put("id",123L);
        map.put("age",100L);
        return R.ok().put("data", map);
    }

    @Login
    @GetMapping("userInfo123")
    @ApiOperation("获取用户信息")
    public R userInfo(@LoginUser UserEntity user){
        return R.ok().put("user", user);
    }

    @Login
    @GetMapping("userId")
    @ApiOperation("获取用户ID")
    public R userInfo(@RequestAttribute("userId") Integer userId){
        return R.ok().put("userId", userId);
    }

    @GetMapping("notToken")
    @ApiOperation("忽略Token验证测试")
    public R notToken(){
        //无token可以访问是因为没有添加@Login注解
        return R.ok().put("msg", "无需token也能访问。。。");
    }

}
